#include "gfviewer.h"
#include "ui_gfviewer.h"

GFViewer::GFViewer(QWidget *parent) :
  QWidget(parent),
  ui(new Ui::GFViewer),
  m_gf(37)
{
  ui->setupUi(this);

  // вывод поля
  QHash<qlonglong, qlonglong> hashTable = m_gf.hashTable();
  QString str = "&nu;<sup>%1</sup>";
  QLabel *lbl;
  QTreeWidgetItem *item = new QTreeWidgetItem(ui->gf);

  lbl = new QLabel( str.arg("-&infin;"));
  lbl->setAlignment(Qt::AlignCenter);
  ui->gf->setItemWidget(item, 0, lbl);

  lbl = new QLabel("0");
  lbl->setAlignment(Qt::AlignCenter);
  ui->gf->setItemWidget(item, 1, lbl);

  lbl = new QLabel( m_gf.toBin(0) );
  lbl->setAlignment(Qt::AlignCenter);
  ui->gf->setItemWidget(item, 2, lbl);

  for (int i = 0; i < hashTable.size(); ++i) {
    item = new QTreeWidgetItem(ui->gf);

    lbl = new QLabel( str.arg(i) );
    lbl->setAlignment(Qt::AlignCenter);
    ui->gf->setItemWidget(item, 0, lbl);

    lbl = new QLabel(  QString::number( hashTable.value(i) )  );
    lbl->setAlignment(Qt::AlignCenter);
    ui->gf->setItemWidget(item, 1, lbl);

    lbl = new QLabel(  m_gf.toBin( hashTable.value(i) )  );
    lbl->setAlignment(Qt::AlignCenter);
    ui->gf->setItemWidget(item, 2, lbl);
  }

  resizeColsTreeWidget(); // подгон размера колонок по содержимому
}

GFViewer::~GFViewer()
{
  delete ui;
}

// подгон размера колонок по содержимому
void GFViewer::resizeColsTreeWidget() const {
  for (int i=0; i < ui->gf->columnCount(); ++i) {
    ui->gf->resizeColumnToContents(i);
  }
}
